package com.neolix.watch.weather;

import android.content.Context;

import com.neolix.watch.bluetooth.BlueToothUtil;
import com.neolix.watch.domain.BaiDuWeatherResult;
import com.neolix.watch.service.BackgroundTaskBase;
import com.neolix.watch.util.SharedPreferencesUtil;

import static com.neolix.watch.util.StringUtil.showText;

public class GetWeatherTask extends BackgroundTaskBase {

    public GetWeatherTask(Context applicationContext) {
        super(applicationContext);
    }

    @Override
    public void execute() {
        //获取天气预报信息
        if (SharedPreferencesUtil.getCurrentLocation() != null)
            new RequestWeatherAsyncTask() {
                @Override
                public void OnResponse(BaiDuWeatherResult httpResponse) {
                    //TODO发送天气数据到手表
                    update(httpResponse);
                }
            }.sendRequest();
    }

    private void update(BaiDuWeatherResult result) {
        if (!result.isCorrectResults()) {
            return;
        }

        BaiDuWeatherResult.BaiDuWeatherData currentWeatherInfo = result.getCurrentWeatherInfo();
        BlueToothUtil.syncWeather(currentWeatherInfo.getWeather(), result.getCurrentTemperatureValue());
    }
}
